how to find largest and smallest element in array